package GameMain.View.Room
{
	import Engine.UIControl.Button;
	
	import GameMain.Game;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	
	import library.SocketData.SocketData;
	
	public class PlayerBox extends Button
	{
		
		public static var STATE_CLOSE:int = 0;
		public static var STATE_NORMAL:int = 1;
		public static var STATE_READY:int = 2;
		
		private var _mc:MovieClip = null;
		private var _playerPosIndex:int = 0;
		private var _playerEntityID:int = 0;
		private var _readyState:Boolean = false;
		
		
		public function PlayerBox(p_content:Sprite)
		{
			super(p_content);
			this.setMoveState(false);
			this._content.mouseChildren = false;
			this.setOnClickFun(this._onMouseClick);
			this._mc = p_content as MovieClip;
			
		}
		
		private function _onMouseClick():void
		{
			
		}
		
		public function get entityID():int
		{
			return this._playerEntityID;
		}
		
		public function setPlayerInfo(data:SocketData):void
		{
			this.setTeamOne();
			this.setReady(data.readInt8());
			this._playerEntityID = data.readInt16();
			if(this._playerEntityID == Game.ownPlayer.entityID)
				Game.ownPlayer.setPlayerRoomIndex(this._playerPosIndex);
			this._mc["LEVEL_TXT"].text = data.readInt8();
			data.readInt8();
			this._mc["NAME_TXT"].text = data.readString();
		}
		
		public function setClose():void
		{
			this._mc.gotoAndStop(4)
			this._mc["LEVEL_TXT"].visible = false;
			this._mc["NAME_TXT"].visible = false;
			this._mc["READY_BT"].visible = false;
			this._mc["FANG_ZHU_BT"].visible = false;
		}
		
		public function setWaiting():void
		{
			this._mc.gotoAndStop(3)
			this._mc["LEVEL_TXT"].visible = false;
			this._mc["NAME_TXT"].visible = false;
			this._mc["READY_BT"].visible = false;
			this._mc["FANG_ZHU_BT"].visible = false;
		}
		
		public function setTeamOne():void
		{
			this._mc.gotoAndStop(1)
			this._mc["LEVEL_TXT"].visible = true;
			this._mc["NAME_TXT"].visible = true;
			this._mc["READY_BT"].visible = false;
			this._mc["FANG_ZHU_BT"].visible = false;
		}
		
		public function setTeamTwo():void
		{
			this._mc.gotoAndStop(2)
			this._mc["LEVEL_TXT"].visible = true;
			this._mc["NAME_TXT"].visible = true;
			this._mc["READY_BT"].visible = false;
			this._mc["FANG_ZHU_BT"].visible = false;
		}
		
		public function setReady(state:int):void
		{
			if(state == STATE_READY)
				this._readyState = true;
			else
				this._readyState = false;
			this._mc["READY_BT"].visible = this._readyState;
		}
		
		public function get isReady():Boolean
		{
			return this._readyState;
		}
		
		public function setMaster(state:int):void
		{
			this._mc["FANG_ZHU_BT"].visible = Boolean(state);
		}
		
		public function setPlayerPosIndex(index:int):void
		{
			this._playerPosIndex = index;
		}
		
		public function setBoxState(state:int):void
		{
			if(state == STATE_CLOSE)
				this.setClose();
			else
				this.setWaiting();
				
		}
		
	}
}